package com.example.mideaoem.data.dehumidificator;

import android.util.Log;

import com.example.mideaoem.data.BaseDevice;
import com.example.mideaoem.data.FactoryDataBody;
import com.example.mideaoem.data.fcCon;

public class DataBodyDeHumiRequest extends FactoryDataBody{

	// 控制类型
//		public byte controlType = 0x40;

		public int humidity_dot;//湿度小数位
		public int humidity;//湿度整数位
		
		public int humidity_set;
		public int humidity_dot_set;
		
		public int windSpeed;
		public int ionSetSwitch;
//		public int timingFuncOn;
		public byte powerMode;
		public byte setMode;
		
		// bit4 定时方式:0-相对定时1-绝对定时
		public byte timingMode;
		// 定时开机时间，分
		public int timingOpenMinute;
		// 定时开－绝对小时
		public int timingOpenHour;
		// 定时开,0- 关,1- 开
		public int timingOpenMark;

		// 第5个字节,定时关机,0x7F表示定时开功能关闭
//		private byte fifthByte = 0x00;
		// 定时关－绝对分
		public int timingCloseMinute;
		// 定时关－绝对小时
		public int timingCloseHour;
		// 定时关,0- 关,1- 开
		public int timingCloseMark;

		// 发送帧累加
		public static byte sendingFrames = 0x01;
		
		public int upanddownSwing;
		public boolean isDisplay;

		private byte[] testData;
		
	@Override
	public byte[] toBytes() {
		// TODO Auto-generated method stub

		fcCon con = new fcCon();
		int[] src = new int[128];
		int[] des = new int[10];
		con.btnSound = 1;
		con.controlSource = 1;
		con.optCommand = 3;
		mOrder ++;
		con.order = mOrder;//要每次不一样
		
		//转换
		con.runStatus = powerMode;
		con.windSpeed = windSpeed;
		con.humidity = humidity_set;
		con.humidity_set_dot = humidity_dot;
		con.mode_F1_return = setMode;
		con.ionSetSwitch = fcCon.ionSet;
		
		con.displayClass = isDisplay?0:7;
		
		/**
		 * 计算定时信息
		 */
		con.timingOffHour = timingCloseHour;
		con.timingOffMinute = timingCloseMinute;
		con.timingOffSwitch = timingCloseMark;
			
		con.timingOnHour = timingOpenHour;
		con.timingOnMinute = timingOpenMinute;
		con.timingOnSwitch = timingOpenMark;
		
		con.timingIsValid = 1;//定时标签  开
		con.timingType = timingMode;
		con.controlSource = 1;
		
		con.upanddownSwing = upanddownSwing;
		
		con.mode_FD_return = this.setMode;
		
		int length = con.stdAirConEx_pro2byte(253, fcCon.CMDTYPE_SET, src, src.length, des, des.length);
		byte[] result = toBytes(src, length);
		testData = result.clone();
		result = addHead(result, fcCon.DEHUMI);
		Log.d("dehumidificator","send --> "+printHexString(result));
		
		return result;
	}

	public byte[] getTestData(){
		if(testData != null){
			return testData;
		}else{
			return new byte[]{};
		}
	}
	
	@Override
	public Object toObject(byte[] bytes) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void setDataBodyStatus(BaseDevice newStatus) {
		if(newStatus instanceof DeHumidification){
			DeHumidification status = (DeHumidification)newStatus;
			this.powerMode = (byte) status.powerMode;//开关
			this.setMode = (byte) status.setMode;//模式
			this.windSpeed = (byte) status.windSpeed;//风速
			this.humidity_dot_set = (byte) status.humidity_dot_set;//湿度
			this.humidity_set = (byte) status.humidity_set;//湿度小数点
			this.isDisplay = status.isDisplay;//屏显
		}
	}
	
}
